<?php
function postCurl($url,$data=[], $token = null,$type = "POST",$content_type='application/json',$is_json=true){
    if($is_json){
        $data  = json_encode($data);
    }
    if(!empty($token)){
        $headerArray =array("Content-type:application/json;charset='utf-8'","Accept:application/json","Authorization:Bearer $token","token:".$token);
    }else{
        $headerArray =array("Content-type:application/json;charset='utf-8'","Accept:application/json");
    }
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);
//        curl_setopt($curl, CURLOPT_POST, 1);
    switch ($type) {
        case "GET":
            curl_setopt($curl, CURLOPT_HTTPGET, true);
            break;
        case "POST":
            curl_setopt($curl, CURLOPT_POST, true);
            break;
        case "PUT"://使用一个自定义的请求信息来代替"GET"或"HEAD"作为HTTP请									                     求。这对于执行"DELETE" 或者其他更隐蔽的HTT
            curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
            break;
        case "DELETE":
            curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
            break;
    }
    //设置请求方法
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
    $httpCode = curl_getinfo($curl,CURLINFO_HTTP_CODE);
    curl_close($curl);
    $return_data = [
        "data" => json_decode($output,true),
        "code" => $httpCode
    ];
    return $return_data;

}